#include"head.h"
//创建子进程 3个
int CreateWorker(int num,WorkDate_t *WorkArr)
{

    bzero(WorkArr,sizeof(WorkArr));//清空操作
    //创建num 个子进程
    for(int i = 0; i< num; i++)
    {
        int fds[2];
        socketpair(AF_UNIX,SOCK_STREAM,0,fds);
        pid_t pid = fork(); //返回值就是子进程的pid
        if(pid==0)
        {
            while(1)   
            {
                close(fds[0]);
                int psockefd;
                WorkArr[i].socketpair = fds[1];
                recvfd(fds[1],&psockefd);//接受到netfd 客户端连接上
                int num = 0;
                num++;
                printf("%d\n",num);
                printf("%d worker,pid = %d, socketfd = %d\n",i,WorkArr[i].pid,fds[1]);
                printf("event is begin\n");
                sleep(3);
                printf("event is over\n");
            }
        }
        close(fds[1]);
        //父进程初始化addr
        WorkArr[i].pid = pid; //父进程的里面，返回值就是pid
        WorkArr[i].states = FREE;
        WorkArr[i].socketpair = fds[0];
        printf("%d worker,pid = %d, socketfd = %d\n",i,WorkArr[i].pid,fds[0]);
    }
    return 0;

}